CREATE procedure amsp_ICDemote
@InSourceNodeID numeric
AS
BEGIN
Declare
@DestSortOrder numeric,
@DestDepth numeric,
@DestID numeric,
@DestAncestorID numeric,
@SourceSortOrder numeric,
@SourceDepth numeric,
@SourceParentID numeric
BEGIN TRANSACTION
SELECT
@SourceSortOrder = SortOrder,
@SourceDepth = CategoryDepth,
@SourceParentID = ParentCategoryID
FROM
Interest_Category
WHERE
InterestCategoryID = @InSourceNodeID
SELECT @DestID = InterestCategoryID,
@DestAncestorID = AncestorCategoryID,
@DestDepth = CategoryDepth
FROM Interest_Category
WHERE SortOrder = (SELECT Max(SortOrder)
FROM Interest_Category
WHERE SortOrder < @SourceSortOrder
AND IsNULL(ParentCategoryID,0) = IsNULL(@SourceParentID,0))
IF @@RowCount = 1 BEGIN
UPDATE Interest_Category
SET ParentCategoryID = @DestID,
AncestorCategoryID = @DestAncestorID
WHERE InterestCategoryID = @InSourceNodeID
EXEC amsp_ICFixTree
END
COMMIT TRANSACTION
END
GO
GRANT EXECUTE ON [dbo].[amsp_ICDemote] TO [IMIS]
GO